/**
 * @param {string} s
 * @return {string}
 * @description 栈
 */

var reverseWords = function (s) {
    // 答案字符串
    let res = ""
    // 栈
    let stack = []
    // 运营数组
    let len = s.length
    for (let i = 0; i < len; i++) {
        // 如果不是空格 就将元素推入数组
        if (s[i] !== " ") {
            stack.push(s[i])
        } else {
            while (stack.length) {
                res += stack.pop()
            }
            res += s[i]
        }
    }
    // 最后如果栈中还有元素 全部放入res
    while (stack.length) {
        res += stack.pop()
    }
    return res
}
reverseWords("Let's take LeetCode contest")